/*******************************************************************************
 * Copyright (c) 2010 liw.
 * All rights reserved. 
 * 
 * This file is part of VanBus.
 * 
 *     VanBus is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 * 
 *     VanBus is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
 * 
 *     You should have received a copy of the GNU General Public License
 *     along with VanBus.  If not, see <http://www.gnu.org/licenses/>.
 * Contributors:
 *     liw - initial API and implementation
 ******************************************************************************/
package org.niclab.vanbus.model.viewadpater;

import java.util.List;

import org.niclab.vanbus.model.BusRoute;

import android.content.Context;
import android.database.Cursor;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ExpandableListAdapter;

public abstract class CommonExpandableListAdapter extends BaseExpandableListAdapter{

	protected BaseExpandableListAdapter delegate;
	
	private Context context;
	private int groupResourceId;
	private int childResourceId;
	
	public CommonExpandableListAdapter(Context ctx, int groupResId, int childResId){
		
		this.context = ctx;
		this.groupResourceId = groupResId;
		this.childResourceId = childResId;
		
	}
	
	
	
	
	public Context getContext() {
		return context;
	}




	public void setContext(Context context) {
		this.context = context;
	}




	public int getGroupResourceId() {
		return groupResourceId;
	}




	public void setGroupResourceId(int groupResourceId) {
		this.groupResourceId = groupResourceId;
	}




	public int getChildResourceId() {
		return childResourceId;
	}




	public void setChildResourceId(int childResourceId) {
		this.childResourceId = childResourceId;
	}




	public BaseExpandableListAdapter getDelegate() {
		return delegate;
	}

	public void updateAdapter(){
		if(delegate!=null)
			delegate.notifyDataSetChanged();
	}
	public void setDelegate(BaseExpandableListAdapter model) {
		this.delegate = model;
		//updateAdapter();
	}

	@Override
	public Object getChild(int groupPosition, int childPosition) {
		if(delegate==null)
			return null;
		return delegate.getChild(groupPosition, childPosition);
	}

	@Override
	public long getChildId(int groupPosition, int childPosition) {
		if(delegate==null)
			return 0;
		return delegate.getChildId(groupPosition, childPosition);
	}

	@Override
	public View getChildView(int groupPosition, int childPosition,
			boolean isLastChild, View convertView, ViewGroup parent) {
		if(delegate==null)
			return null;
		return delegate.getChildView(groupPosition, childPosition, isLastChild, convertView, parent);
	}

	@Override
	public int getChildrenCount(int groupPosition) {
		if(delegate==null)
			return 0;
		return delegate.getChildrenCount(groupPosition);
	}

	@Override
	public Object getGroup(int groupPosition) {
		if(delegate==null)
			return null;
		return delegate.getGroup(groupPosition);
	}

	@Override
	public int getGroupCount() {
		if(delegate==null)
			return 0;
		return delegate.getGroupCount();
	}

	@Override
	public long getGroupId(int groupPosition) {
		if(delegate==null)
			return 0;
		return delegate.getGroupId(groupPosition);
	}

	@Override
	public View getGroupView(int groupPosition, boolean isExpanded,
			View convertView, ViewGroup parent) {
		if(delegate==null)
			return null;
		
		return delegate.getGroupView(groupPosition, isExpanded, convertView, parent);
	}

	@Override
	public boolean hasStableIds() {
		if(delegate==null)
			return false;
		return delegate.hasStableIds();
	}

	@Override
	public boolean isChildSelectable(int groupPosition, int childPosition) {
		if(delegate==null)
			return false;
		
		return delegate.isChildSelectable(groupPosition, childPosition);
	}
	
	
	public abstract void setChildrenList(int groupPosition, List children);
	
	public void setChildrenCursor(int groupPosistion, Cursor cursor){
		//TODO
	}

}
